<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        function fn() {
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    console.log("第一步");
                    // 使用resolve把需要的数据返回
                    // 可以使任意类型，常用：ajax请求返回的数据可以在这里返回
                    var data = {
                        name: '张三',
                        age: 18
                    }
                    resolve(data);
                }, 1000)
            })
        }

        (async function () {
            // 使用变量接受resolve函数的返回值
            var result = await fn();
            console.log(result);
        })();
    </script>
</body>
</html>